package com.mall.db.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mall.db.mapper.UmsRoleResourceRelationMapper;
import com.mall.pojo.UmsRoleResourceRelation;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class UmsRoleResourceRelationApiImpl implements UmsRoleResourceRelationApi {

    @Autowired
    private UmsRoleResourceRelationMapper roleResourceRelationMapper;

    @Override
    public List<UmsRoleResourceRelation> findByRole(Long roleId) {
        LambdaQueryWrapper<UmsRoleResourceRelation> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UmsRoleResourceRelation::getRoleId, roleId);
        return roleResourceRelationMapper.selectList(wrapper);
    }

    @Override
    public void delete(Integer roleId) {
        LambdaQueryWrapper<UmsRoleResourceRelation> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UmsRoleResourceRelation::getRoleId, roleId);
        roleResourceRelationMapper.delete(wrapper);
    }

    @Override
    public void add(UmsRoleResourceRelation relation) {
        roleResourceRelationMapper.insert(relation);
    }
}
